package com.spsy.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spsy.common.log.annotation.Log;
import com.spsy.common.log.enums.BusinessType;
import com.spsy.common.security.annotation.RequiresPermissions;
import com.spsy.system.domain.CategoryInfo;
import com.spsy.system.service.ICategoryInfoService;
import com.spsy.common.core.web.controller.BaseController;
import com.spsy.common.core.web.domain.AjaxResult;
import com.spsy.common.core.utils.poi.ExcelUtil;

/**
 * 品类信息Controller
 * @author arhat
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/category")
public class CategoryInfoController extends BaseController
{
    @Autowired
    private ICategoryInfoService categoryInfoService;

    /**
     * 查询品类信息列表
     */
    @RequiresPermissions("system:category:list")
    @GetMapping("/list")
    public AjaxResult list(CategoryInfo categoryInfo)
    {
        List<CategoryInfo> list = categoryInfoService.selectCategoryInfoList(categoryInfo);
        return success(list);
    }

    /**
     * 导出品类信息列表
     */
    @RequiresPermissions("system:category:export")
    @Log(title = "品类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CategoryInfo categoryInfo)
    {
        List<CategoryInfo> list = categoryInfoService.selectCategoryInfoList(categoryInfo);
        ExcelUtil<CategoryInfo> util = new ExcelUtil<CategoryInfo>(CategoryInfo.class);
        util.exportExcel(response, list, "品类信息数据");
    }

    /**
     * 获取品类信息详细信息
     */
    @RequiresPermissions("system:category:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(categoryInfoService.selectCategoryInfoById(id));
    }

    /**
     * 新增品类信息
     */
    @RequiresPermissions("system:category:add")
    @Log(title = "品类信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryInfo categoryInfo)
    {
        return toAjax(categoryInfoService.insertCategoryInfo(categoryInfo));
    }

    /**
     * 修改品类信息
     */
    @RequiresPermissions("system:category:edit")
    @Log(title = "品类信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryInfo categoryInfo)
    {
        return toAjax(categoryInfoService.updateCategoryInfo(categoryInfo));
    }

    /**
     * 删除品类信息
     */
    @RequiresPermissions("system:category:remove")
    @Log(title = "品类信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(categoryInfoService.deleteCategoryInfoByIds(ids));
    }
}
